package com.andox.fn.inf.rpc.rest.util;


import org.apache.commons.lang3.StringUtils;

import com.google.common.base.Preconditions;

/**   
 * @ClassName:   RegistryUtil   
 * @Description: TODO  
 * @author:      Andox
 * @date:        2019年8月16日 上午11:38:52   
 *     
 */
public class RegistryUtil {
	public static String findRegistryProtocol(String registry) {
		Preconditions.checkArgument(registry != null, "registry is empty");
		
		String protocol = "zookeeper";
		String tmp = registry.trim();
		int index = tmp.indexOf("://");
		if (index == -1) {
			// default registry zookeeper
		} else {
			protocol = tmp.substring(0, index);
			Preconditions.checkArgument(StringUtils.isNoneBlank(protocol), "registry is empty");
		}
		
		return protocol;
	}
	
	public static String findRegistryConnection(String registry) {
		Preconditions.checkArgument(registry != null, "registry is empty");
		
		String tmp = registry.trim();
		int index = tmp.indexOf("://");
		if (index == -1) {
			// default registry zookeeper
			return registry;
		} else {
			registry = tmp.substring(index + 3);
			Preconditions.checkArgument(StringUtils.isNoneBlank(registry), "registry is empty");
		}
		
		return registry;
	}
}
